package cn.ittiger.player.demo;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.view.SimpleDraweeView;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import cn.ittiger.player.PlayerManager;
import cn.ittiger.player.VideoPlayerView;

public class MainActivity extends AppCompatActivity {
    VideoPlayerView mPlayerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        Fresco.initialize(this);
        setContentView(R.layout.activity_main);
        mPlayerView = (VideoPlayerView) findViewById(R.id.video_player_view);


        VideoBean videoBean = VideoData.getVideo();
        mPlayerView.bind(videoBean.getVideoUrl(), videoBean.getVideoTitle());
        mPlayerView.getThumbImageView().setScaleType(ImageView.ScaleType.FIT_XY);
        ((SimpleDraweeView)mPlayerView.getThumbImageView()).setImageURI(Uri.parse(videoBean.getVideoThumbUrl()));
    }

    public void onClick(View view) {

        int id = view.getId();
        switch (id) {
            case R.id.video_in_recyclerView:
                startActivity(new Intent(this, RecyclerViewVideoActivity.class));
                break;
            case R.id.video_in_viewpager_fragment:
                startActivity(new Intent(this, ViewPagerFragmentActivity.class));
                break;
            case R.id.full_screen_play:
                startActivity(new Intent(this, FullScreenActivity.class));
                break;
        }
    }

    @Override
    protected void onResume() {

        super.onResume();
        PlayerManager.getInstance().resume();
    }

    @Override
    protected void onPause() {

        super.onPause();
        PlayerManager.getInstance().pause();
    }

    @Override
    protected void onDestroy() {

        super.onDestroy();
        PlayerManager.getInstance().release();
    }

    @Override
    public void onBackPressed() {

        if(PlayerManager.getInstance().onBackPressed() == false) {
            super.onBackPressed();
        }
    }
}
